﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace SpringStudio.DAL
{
    internal static class ValidationCheck
    {
        /// <summary>
        /// 检查数据库事务
        /// </summary>
        /// <param name="transaction">事务参数</param>
        public static void Transaction(IDbTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction", "参数transaction不能为空！");
            }

            if (transaction.Connection == null)
            {
                throw new ArgumentNullException("transaction", "参数transaction的连接失效");
            }
        }

        /// <summary>
        /// 检查数据库连接字符串
        /// </summary>
        /// <param name="connectString">数据库连接字符串</param>
        public static void ConnectString(string connectString)
        {
            if (connectString == null || connectString.Trim().Length == 0)
            {
                throw new ArgumentNullException("connectString", "参数connectString不能为空或空字符串！");
            }
        }

        /// <summary>
        /// 检查数据库连接
        /// </summary>
        /// <param name="connection">数据库连接对象</param>
        public static void Connection(IDbConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection", "参数connection不能为空");
            }
        }

        /// <summary>
        /// 检查命令对象
        /// </summary>
        /// <param name="command">命令对象</param>
        public static void Command(IDbCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command", "参数command不能为空");
            }
        }

        /// <summary>
        /// 检查SQL语句
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        public static void CommandText(string commandText)
        {
            if (commandText == null || commandText.Trim().Length == 0)
            {
                throw new ArgumentNullException("commandText", "参数commandText不能为空");
            }
        }

        /// <summary>
        /// 检查参数名称
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        public static void ParameterName(string parameterName)
        {
            if (parameterName == null || parameterName.Trim().Length == 0)
            {
                throw new ArgumentNullException("parameterName", "参数parameterName不能为空");
            }
        }
    }
}
